

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.param.dataio_param &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.param.dataio_param</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.param.dataio_param</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">federatedml.param.base_param</span> <span class="k">import</span> <span class="n">BaseParam</span>


<div class="viewcode-block" id="DataIOParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.dataio_param.DataIOParam">[docs]</a><span class="k">class</span> <span class="nc">DataIOParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define dataio parameters that used in federated ml.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    input_format : str, accepted &#39;dense&#39;,&#39;sparse&#39; &#39;tag&#39; only in this version. default: &#39;dense&#39;</span>

<span class="sd">    delimitor : str, the delimitor of data input, default: &#39;,&#39;</span>

<span class="sd">    data_type : str, the data type of data input, accedted &#39;float&#39;,&#39;float64&#39;,&#39;int&#39;,&#39;int64&#39;,&#39;str&#39;,&#39;long&#39;</span>
<span class="sd">               &quot;default: &quot;float64&quot;</span>

<span class="sd">    tag_with_value: bool, use if input_format is &#39;tag&#39;, if tag_with_value is True, input column data format should be tag[delimitor]value, otherwise is tag only</span>

<span class="sd">    tag_value_delimitor: str, use if input_format is &#39;tag&#39; and &#39;tag_with_value&#39; is True, delimitor of tag[delimitor]value column value.</span>

<span class="sd">    missing_fill : bool, need to fill missing value or not, accepted only True/False, default: True</span>

<span class="sd">    default_value : None or single object type or list, the value to replace missing value.</span>
<span class="sd">                    if None, it will use default value define in federatedml/feature/imputer.py,</span>
<span class="sd">                    if single object, will fill missing value with this object,</span>
<span class="sd">                    if list, it&#39;s length should be the sample of input data&#39; feature dimension,</span>
<span class="sd">                        means that if some column happens to have missing values, it will replace it</span>
<span class="sd">                        the value by element in the identical position of this list.</span>
<span class="sd">                    default: None</span>

<span class="sd">    missing_fill_method: None or str, the method to replace missing value, should be one of [None, &#39;min&#39;, &#39;max&#39;, &#39;mean&#39;, &#39;designated&#39;], default: None</span>

<span class="sd">    missing_impute: None or list, element of list can be any type, or auto generated if value is None, define which values to be consider as missing, default: None</span>

<span class="sd">    outlier_replace: bool, need to replace outlier value or not, accepted only True/False, default: True</span>

<span class="sd">    outlier_replace_method: None or str, the method to replace missing value, should be one of [None, &#39;min&#39;, &#39;max&#39;, &#39;mean&#39;, &#39;designated&#39;], default: None</span>

<span class="sd">    outlier_impute: None or list,  element of list can be any type, which values should be regard as missing value, default: None</span>

<span class="sd">    outlier_replace_value: None or single object type or list, the value to replace outlier.</span>
<span class="sd">                    if None, it will use default value define in federatedml/feature/imputer.py,</span>
<span class="sd">                    if single object, will replace outlier with this object,</span>
<span class="sd">                    if list, it&#39;s length should be the sample of input data&#39; feature dimension,</span>
<span class="sd">                        means that if some column happens to have outliers, it will replace it</span>
<span class="sd">                        the value by element in the identical position of this list.</span>
<span class="sd">                    default: None</span>

<span class="sd">    with_label : bool, True if input data consist of label, False otherwise. default: &#39;false&#39;</span>

<span class="sd">    label_idx : int, accepted &#39;int&#39;,&#39;long&#39; only, use when with_label is True. default: &#39;false&#39;</span>

<span class="sd">    label_type : object, accepted &#39;int&#39;,&#39;int64&#39;,&#39;float&#39;,&#39;float64&#39;,&#39;long&#39;,&#39;str&#39; only,</span>
<span class="sd">                use when with_label is True. default: &#39;false&#39;</span>

<span class="sd">    output_format : str, accepted &#39;dense&#39;,&#39;sparse&#39; only in this version. default: &#39;dense&#39;</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">input_format</span><span class="o">=</span><span class="s2">&quot;dense&quot;</span><span class="p">,</span> <span class="n">delimitor</span><span class="o">=</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="n">data_type</span><span class="o">=</span><span class="s1">&#39;float64&#39;</span><span class="p">,</span>
                 <span class="n">tag_with_value</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">tag_value_delimitor</span><span class="o">=</span><span class="s2">&quot;:&quot;</span><span class="p">,</span>
                 <span class="n">missing_fill</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">default_value</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">missing_fill_method</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">missing_impute</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">outlier_replace</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">outlier_replace_method</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">outlier_impute</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">outlier_replace_value</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                 <span class="n">with_label</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">label_idx</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                 <span class="n">label_type</span><span class="o">=</span><span class="s1">&#39;int&#39;</span><span class="p">,</span> <span class="n">output_format</span><span class="o">=</span><span class="s1">&#39;dense&#39;</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">input_format</span> <span class="o">=</span> <span class="n">input_format</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delimitor</span> <span class="o">=</span> <span class="n">delimitor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_type</span> <span class="o">=</span> <span class="n">data_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tag_with_value</span> <span class="o">=</span> <span class="n">tag_with_value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tag_value_delimitor</span> <span class="o">=</span> <span class="n">tag_value_delimitor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">missing_fill</span> <span class="o">=</span> <span class="n">missing_fill</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">default_value</span> <span class="o">=</span> <span class="n">default_value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">missing_fill_method</span> <span class="o">=</span> <span class="n">missing_fill_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">missing_impute</span> <span class="o">=</span> <span class="n">missing_impute</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outlier_replace</span> <span class="o">=</span> <span class="n">outlier_replace</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outlier_replace_method</span> <span class="o">=</span> <span class="n">outlier_replace_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outlier_impute</span> <span class="o">=</span> <span class="n">outlier_impute</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outlier_replace_value</span> <span class="o">=</span> <span class="n">outlier_replace_value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">with_label</span> <span class="o">=</span> <span class="n">with_label</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">label_idx</span> <span class="o">=</span> <span class="n">label_idx</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">label_type</span> <span class="o">=</span> <span class="n">label_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">output_format</span> <span class="o">=</span> <span class="n">output_format</span>

<div class="viewcode-block" id="DataIOParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.dataio_param.DataIOParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;dataio param&#39;s&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">input_format</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">input_format</span><span class="p">,</span>
                                                        <span class="p">[</span><span class="s2">&quot;dense&quot;</span><span class="p">,</span> <span class="s2">&quot;sparse&quot;</span><span class="p">,</span> <span class="s2">&quot;tag&quot;</span><span class="p">],</span>
                                                        <span class="n">descr</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">output_format</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">output_format</span><span class="p">,</span>
                                                         <span class="p">[</span><span class="s2">&quot;dense&quot;</span><span class="p">,</span> <span class="s2">&quot;sparse&quot;</span><span class="p">],</span>
                                                         <span class="n">descr</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_type</span><span class="p">,</span>
                                                     <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;int64&quot;</span><span class="p">,</span> <span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;float64&quot;</span><span class="p">,</span> <span class="s2">&quot;str&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">],</span>
                                                     <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">missing_fill</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s1">&#39;bool&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;dataio param&#39;s missing_fill </span><span class="si">{}</span><span class="s2"> not supported&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">missing_fill</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">missing_fill_method</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">missing_fill_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">missing_fill_method</span><span class="p">,</span>
                                                                   <span class="p">[</span><span class="s1">&#39;min&#39;</span><span class="p">,</span> <span class="s1">&#39;max&#39;</span><span class="p">,</span> <span class="s1">&#39;mean&#39;</span><span class="p">,</span> <span class="s1">&#39;designated&#39;</span><span class="p">],</span>
                                                                   <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">outlier_replace_method</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">outlier_replace_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">outlier_replace_method</span><span class="p">,</span>
                                                                      <span class="p">[</span><span class="s1">&#39;min&#39;</span><span class="p">,</span> <span class="s1">&#39;max&#39;</span><span class="p">,</span> <span class="s1">&#39;mean&#39;</span><span class="p">,</span> <span class="s1">&#39;designated&#39;</span><span class="p">],</span>
                                                                      <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">with_label</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s1">&#39;bool&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;dataio param&#39;s with_label </span><span class="si">{}</span><span class="s2"> not supported&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">with_label</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_label</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">label_idx</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;long&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">]:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;dataio param&#39;s label_idx </span><span class="si">{}</span><span class="s2"> not supported&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">label_idx</span><span class="p">))</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">label_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">label_type</span><span class="p">,</span>
                                                          <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;int64&quot;</span><span class="p">,</span> <span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;float64&quot;</span><span class="p">,</span> <span class="s2">&quot;str&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">],</span>
                                                          <span class="n">descr</span><span class="p">)</span>

        <span class="k">return</span> <span class="kc">True</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>